using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Xeml.Document.Contracts;
using Xeml.Document;
using System.IO;
using System.Drawing.Imaging;

namespace Xid.Controls
{
    public partial class HeaderEdtCtrl : UserControl
    {

        private BindingSource _keywordsBindingSource;
        public HeaderEdtCtrl()
        {
            InitializeComponent();
            buttonSpecAddKeyword.Click += new EventHandler(OnAddKeyword);
            buttonSpecDeleteKeyword.Click += new EventHandler(OnDeleteKeyword_Click);


            //ExtractReportFiles();
        }

       

        void OnAddKeyword(object sender, EventArgs e)
        {
            if (_keywordsBindingSource != null)
            {
                _keywordsBindingSource.AddNew();
            }
        }

        void OnDeleteKeyword_Click(object sender, EventArgs e)
        {
            if (_keywordsBindingSource != null && _keywordsBindingSource.Current != null)
            {
                _keywordsBindingSource.RemoveCurrent();
            }
        }

        private IDocument _xemlDoc;
        public void Setup(IDocument xemlDoc)
        {
            _keywordsBindingSource = null;
            _xemlDoc = xemlDoc;
            textBoxFirstName.DataBindings.Clear();
            textBoxLastName.DataBindings.Clear();
            textBoxEmail.DataBindings.Clear();
            textBoxOrganisation.DataBindings.Clear();
            textBoxDescription.DataBindings.Clear();

            if (xemlDoc != null)
            {
                textBoxFirstName.DataBindings.Add("Text", xemlDoc.ExperimentHeader.Experimenter, "FirstName", true, DataSourceUpdateMode.OnValidation);
                textBoxLastName.DataBindings.Add("Text", xemlDoc.ExperimentHeader.Experimenter, "LastName", true, DataSourceUpdateMode.OnValidation);
                textBoxEmail.DataBindings.Add("Text", xemlDoc.ExperimentHeader.Experimenter, "EMail", true, DataSourceUpdateMode.OnValidation);
                textBoxOrganisation.DataBindings.Add("Text", xemlDoc.ExperimentHeader.Experimenter, "Organisation", true, DataSourceUpdateMode.OnValidation);

                textBoxDescription.DataBindings.Add("Text", xemlDoc.ExperimentHeader, "Description", true, DataSourceUpdateMode.OnValidation);

          
                BindingList<Keyword> bl = new BindingList<Keyword>(_xemlDoc.ExperimentHeader.Keywords);
                bl.AllowNew = true;
               
                _keywordsBindingSource = new BindingSource();
                //bs.DataMember = "Value";
                _keywordsBindingSource.DataSource = bl;
               // bindingNavigator1.BindingSource = bs;
                kryptonDataGridViewKeywords.DataSource = _keywordsBindingSource;
                //GenerateReport();
            }
        }
    }
}
